/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author The Lunatics
 */
@Entity
@Table(name = "user_has_account")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "UserHasAccount.findAll", query = "SELECT u FROM UserHasAccount u"),
    @NamedQuery(name = "UserHasAccount.findByUserId", query = "SELECT u FROM UserHasAccount u WHERE u.userHasAccountPK.userId = :userId"),
    @NamedQuery(name = "UserHasAccount.findByAccountNumber", query = "SELECT u FROM UserHasAccount u WHERE u.userHasAccountPK.accountNumber = :accountNumber")})
public class UserHasAccount implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected UserHasAccountPK userHasAccountPK;
    @OneToMany(mappedBy = "userHasAccount")
    private Collection<Purchases> purchasesCollection;
    @JoinColumn(name = "User_Id", referencedColumnName = "User_Id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Users users;
    @JoinColumn(name = "Account_Number", referencedColumnName = "Account_Number", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Accounts accounts;

    public UserHasAccount() {
    }

    public UserHasAccount(UserHasAccountPK userHasAccountPK) {
        this.userHasAccountPK = userHasAccountPK;
    }

    public UserHasAccount(int userId, int accountNumber) {
        this.userHasAccountPK = new UserHasAccountPK(userId, accountNumber);
    }

    public UserHasAccountPK getUserHasAccountPK() {
        return userHasAccountPK;
    }

    public void setUserHasAccountPK(UserHasAccountPK userHasAccountPK) {
        this.userHasAccountPK = userHasAccountPK;
    }

    @XmlTransient
    public Collection<Purchases> getPurchasesCollection() {
        return purchasesCollection;
    }

    public void setPurchasesCollection(Collection<Purchases> purchasesCollection) {
        this.purchasesCollection = purchasesCollection;
    }

    public Users getUsers() {
        return users;
    }

    public void setUsers(Users users) {
        this.users = users;
    }

    public Accounts getAccounts() {
        return accounts;
    }

    public void setAccounts(Accounts accounts) {
        this.accounts = accounts;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userHasAccountPK != null ? userHasAccountPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UserHasAccount)) {
            return false;
        }
        UserHasAccount other = (UserHasAccount) object;
        if ((this.userHasAccountPK == null && other.userHasAccountPK != null) || (this.userHasAccountPK != null && !this.userHasAccountPK.equals(other.userHasAccountPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.UserHasAccount[ userHasAccountPK=" + userHasAccountPK + " ]";
    }
    
}
